﻿# coding=utf-8
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, SelectField, RadioField, SelectMultipleField, BooleanField, TextAreaField
from wtforms.validators import DataRequired, Length, EqualTo, Email, ValidationError

from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap


class addsysopt(FlaskForm):
    type = SelectField(label='类型:',
                       validators=[DataRequired(message=u'请选择类型')],
                       render_kw={
                           'class': 'form-control',
                       },
                       choices=[(1, '服务器组'), ('2', '帐号'), ('3', '其它参数'), ('4', '脚本')],
                       default=1,
                       coerce=int
                       )

    name = StringField(label='名称',
                       validators=[DataRequired(message="用户名必须输入")],
                       render_kw={
                           'placeholder': 'name',
                           'class': 'form-control'
                       })
    value = TextAreaField(label='值',
                          validators=[DataRequired()],
                          render_kw={
                              'placeholder': 'value',
                              'rows': '3',
                              'class': 'form-control'
                          })
    desc = StringField(label='描述',
                       render_kw={
                           'placeholder': 'desc',
                           'class': 'form-control'
                       })
    submit = SubmitField('提交', render_kw={
        'class': 'btn btn-primary'
    })


class addservers(FlaskForm):
    hostname = StringField(label='主机名',
                           validators=[DataRequired(message='请输入主机名称')],
                           default='',
                           render_kw={
                               'placeholder': 'hostname',
                               'class': 'form-control'
                           })
    ipaddr = StringField(label='IP地扯',
                         validators=[DataRequired(message='请填写IP地扯')],
                         render_kw={
                             'placeholder': 'IP地扯',
                             'class': 'form-control'
                         })
    username = StringField(label='用户名',
                           validators=[DataRequired()],
                           render_kw={
                               'placeholder': '主机登陆用户名',
                               'class': 'form-control'
                           })
    password = StringField(label='登陆密码',
                           validators=[DataRequired()],
                           render_kw={
                               'placeholder': '主机登陆密码',
                               'class': 'form-control'
                           })
    sshport = StringField(label='SSH端口',
                          validators=[DataRequired()],
                          render_kw={
                              'placeholder': 'SSH端口',
                              'class': 'form-control'
                          })
    groups = SelectField(label='设备组:',
                         validators=[DataRequired('请选择设备组')],
                         render_kw={
                             'class': 'form-control',
                         },
                         choices=[],
                         default=3,
                         coerce=int
                         )
    Desc = StringField(label='描述',
                       validators=[DataRequired()],
                       render_kw={
                           'placeholder': '描述',
                           'class': 'form-control'
                       })
    submit = SubmitField('提交', render_kw={
        'class': 'btn btn-primary'
    })


class addprojects(FlaskForm):
    project = StringField(label='项目名称',
                          validators=[DataRequired(message=u'项目名称不能为空')],
                          render_kw={
                              'placeholder': 'type',
                              'class': 'form-control'
                          })
    Repo = StringField(label='Git地扯',
                       validators=[DataRequired(message=u'Git地扯不能为空')],
                       render_kw={
                           'placeholder': 'ipaddr',
                           'class': 'form-control'
                       })
    evn = StringField(label='项目环境',
                      validators=[DataRequired()],
                      render_kw={
                          'placeholder': 'value',
                          'class': 'form-control'
                      })
    path = StringField(label='项目路径',
                       validators=[DataRequired()],
                       render_kw={
                           'placeholder': 'desc',
                           'class': 'form-control'
                       })
    servers = SelectMultipleField(label='服务器:',
                                  validators=[DataRequired(message='请选择设备组')],
                                  render_kw={
                                      'class': 'form-control',
                                  },
                                  choices=[],
                                  default=10,
                                  coerce=int
                                  )
    remember = BooleanField('Remember me')
    checkzip = RadioField('certification', choices=['编译', 'option2'])
    submit = SubmitField('提交', render_kw={
        'class': 'btn btn-primary'
    })


class runshell(FlaskForm):
    shell = StringField(label='shell',
                        validators=[DataRequired(message='shell')],
                        render_kw={
                            'placeholder': 'shell',
                            'class': 'form-control'
                        })
    servers = SelectMultipleField(label='服务器:',
                                  validators=[DataRequired('请选择设备组')],
                                  render_kw={
                                      'class': 'form-control',
                                  },
                                  choices=[],
                                  default=10,
                                  coerce=int
                                  )
    submit = SubmitField('执行', render_kw={
        'class': 'btn btn-primary'
    })
